package cn.ac.iscas.service.patent;

import java.io.File;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.ac.iscas.bean.base.DAOSupport;
import cn.ac.iscas.bean.base.DeleteDocument;
import cn.ac.iscas.bean.patent.PatentPicture;
@Service
@Transactional
public class PatentPictureServiceImp extends DAOSupport<PatentPicture>
implements IPatentPictureService{
	@Override
	public void delete(Object entity) {
		PatentPicture picture = (PatentPicture)entity;
		deleteDocument(picture.getRealName());
		System.out.println(picture.getId());
		picture = (PatentPicture)sessionFactory.getCurrentSession().get(PatentPicture.class, picture.getId());
		sessionFactory.getCurrentSession().delete(picture);
	}
	private void deleteDocument(String file)
	{
		String realPath =  ServletActionContext.getServletContext().getRealPath("/patentPictures");
	    file = realPath+"/"+file;
	    File deleteFile = new File(file);
	    deleteFile.delete();
	}
}
